﻿using Abp.Application.Services;
using Abp.Dependency;
using Abp.Domain.Repositories;
using Abp.Domain.Uow;
using Abp.Runtime.Caching;
using AbpBuild.BaseData;
using AbpBuild.LawManage;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;


namespace AbpBuild.WenShu
{
	/// <summary>
	/// 数据提供
	/// </summary>
	public class BaseDatasHelper : AbpBuildAppServiceBase, IBaseDatasHelper, ITransientDependency
	{
		
		private readonly IRepository<courtFullName, string> _courtFullName; //in the first db
		private readonly IRepository<caseReason, string> _caseReason; //in the first db
		private readonly ICacheManager _cacheManager;
		private readonly IRepository<LawKeyWords, string> _lawkeywordsrepository; //in the second db

		private readonly IRepository<LawType, string> _LawType; //in the first db
		private readonly IRepository<LawAuthority, string> _LawAuthority; //in the first db
		private readonly IRepository<Laweff_level, string> _Laweff_level; //in the first db
		private readonly IRepository<LawjudgeProcess, string> _LawjudgeProcess; //in the first db
		private readonly IRepository<LawDXtype, string> _LawDXtype; //in the first db

		public BaseDatasHelper(
            IRepository<courtFullName, string> courtFullName,
            IRepository<caseReason, string> caseReason, 
            IRepository<LawKeyWords, string> lawkeywords,
            IRepository<LawType, string> LawType,
			IRepository<LawAuthority, string> LawAuthority,
            IRepository<Laweff_level, string> Laweff_level,
            IRepository<LawjudgeProcess, string> LawjudgeProcess,
            IRepository<LawDXtype, string> LawDXtype,
			ICacheManager cacheManager)
        {
            _lawkeywordsrepository = lawkeywords;
            _courtFullName = courtFullName;
			_caseReason = caseReason;
			_LawType = LawType;
			_LawAuthority = LawAuthority;
			_Laweff_level = Laweff_level;
			_LawjudgeProcess = LawjudgeProcess;
			_LawDXtype = LawDXtype;
            _cacheManager = cacheManager;
        }


		/// <summary>
		/// 获取关键字
		/// </summary>
		/// <returns></returns>
		[RemoteService(false)]
		public List<string> getkeywords(int top =10)
		{
			string key = "getkeywords" + top.ToString();
			var keywords = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
            if (keywords == null)
            {
                keywords = _lawkeywordsrepository.GetAll().AsNoTracking().Select(p => p.Name).ToList<string>();
				_cacheManager.GetCache("BaseDatasHelper").Set(key, keywords, null, new TimeSpan(1, 0, 0, 0));
            }

            //var keywords = _lawkeywordsrepository.GetAll().AsNoTracking().Select(p => p.Name).ToList<string>();

            if (top > 0)
			{
				return ((List<string>)keywords).Take(top).ToList();
			}
			return (List<string>)keywords;
		}


        /// <summary>
        /// 获取法律大小类：当level为第一级时为大类对应type，第二级为小类对应subtype
        /// </summary>
        /// <returns></returns>
        [RemoteService(false)]
        public List<LawDXtype> GetLawDXtype(string name = null,int? level = null)
		{
			//string key = "GetLawDXtype" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
   //         var LawDXtypes = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
   //         if (LawDXtypes == null)
   //         {
   //             //LawDXtypes = _LawDXtype.GetAllIncluding(m => m.parentLawDXtype, m => m.childLawDXtype).ToList();
   //             LawDXtypes = _LawDXtype.GetAll().AsNoTracking().ToList();
   //             _cacheManager.GetCache("BaseDatasHelper").Set(key, LawDXtypes, null, new TimeSpan(1, 0, 0, 0));
			//}
            var LawDXtypes = _LawDXtype.GetAllIncluding(m => m.parentLawDXtype, m => m.childLawDXtype).ToList();

			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					return ((List<LawDXtype>)LawDXtypes).ToList();

				}
				else
				{
					return ((List<LawDXtype>)LawDXtypes).Where(p => p.levels == level).ToList();

				}
			}
			else
			{
				if (level == null)
				{
					return ((List<LawDXtype>)LawDXtypes).Where(p => p.name.Contains(name)).ToList();

				}
				else
				{
					return ((List<LawDXtype>)LawDXtypes).Where(p => p.name.Contains(name) && p.levels == level).ToList();
				}

			}
		}
	
		/// <summary>
		/// 获取法律大小类：当level为第一级时为大类对应type，第二级为小类对应subtype
		/// </summary>
		/// <returns></returns>
		public List<LawDXtype> GetLawDXtypeOUT(string name = null, int? level = null)
		{
            try
            {
				//string key = "GetLawDXtypeOUT" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //            var LawDXtypes = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //            if (LawDXtypes == null)
    //            {
    //                //LawDXtypes = _LawDXtype.GetAllIncluding(m => m.parentLawDXtype, m => m.childLawDXtype).ToList();
    //                LawDXtypes = _LawDXtype.GetAll().AsNoTracking().ToList();
    //                _cacheManager.GetCache("BaseDatasHelper").Set(key, LawDXtypes, null, new TimeSpan(1, 0, 0, 0));
    //            }

                var LawDXtypes = _LawDXtype.GetAllIncluding(m => m.parentLawDXtype, m => m.childLawDXtype).ToList();

				List<LawDXtype> CS = (List<LawDXtype>)LawDXtypes;
				
				List<LawDXtype> re = new List<LawDXtype>();
				LawDXtype law;
				foreach (var item in CS)
				{
					law = new LawDXtype() { Id = item.Id, levels = item.levels, name = item.name, pid = item.pid };
					if (item.childLawDXtype != null && item.childLawDXtype.Count > 0)
					{
						foreach (var item2 in item.childLawDXtype)
						{
							LawDXtype law2 = new LawDXtype() { Id = item2.Id, levels = item2.levels, name = item2.name, pid = item2.pid };
							if (item2.childLawDXtype != null && item2.childLawDXtype.Count > 0)
							{
								foreach (var item3 in item2.childLawDXtype)
								{
									LawDXtype law3 = new LawDXtype() { Id = item3.Id, levels = item3.levels, name = item3.name, pid = item3.pid };
									if (item3.childLawDXtype != null && item3.childLawDXtype.Count > 0)
									{
										foreach (var item4 in item3.childLawDXtype)
										{
											LawDXtype law4 = new LawDXtype() { Id = item4.Id, levels = item4.levels, name = item4.name, pid = item4.pid };
											if (item4.childLawDXtype != null && item4.childLawDXtype.Count > 0)
											{
												foreach (var item5 in item4.childLawDXtype)
												{
													LawDXtype law5 = new LawDXtype() { Id = item5.Id, levels = item5.levels, name = item5.name, pid = item5.pid };
													if (item5.childLawDXtype != null && item5.childLawDXtype.Count > 0)
													{
														foreach (var item6 in item5.childLawDXtype)
														{
															LawDXtype law6 = new LawDXtype() { Id = item6.Id, levels = item6.levels, name = item6.name, pid = item6.pid };
															law5.childLawDXtype.Add(law6);
														}
													}
													law4.childLawDXtype.Add(law5);

												}
											}
											law3.childLawDXtype.Add(law4);

										}
									}
									law2.childLawDXtype.Add(law3);

								}
							}
							law.childLawDXtype.Add(law2);

						}
					}
					re.Add(law);
				}
				if (string.IsNullOrEmpty(name))
				{
					if (level == null)
					{
						re = re.ToList();

					}
					else
					{
						re = re.Where(p => p.levels == level).ToList();
					}
				}
				else
				{
					if (level == null)
					{
						re = re.Where(p => p.name != null && p.name.Contains(name)).ToList();

					}
					else
					{
						re = re.Where(p => p.name != null && p.name.Contains(name) && p.levels == level).ToList();
					}
				}
				return re;

			}
            catch (Exception ex)
            {

                throw;
            }
			

		}





		/// <summary>
		/// 第一级为审判类型，子集为审判流程
		/// </summary>
		/// <returns></returns>
		[RemoteService(false)]
		public List<LawjudgeProcess> GetjudgeProcess(string name = null, int? level = null)
		{
			//string key = "GetjudgeProcess" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
   //         var LawjudgeProcesss = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
   //         if (LawjudgeProcesss == null)
   //         {
   //             //LawjudgeProcesss = _LawjudgeProcess.GetAllIncluding(m => m.parentLawjudgeProcess, m => m.childLawjudgeProcess).ToList();
   //             LawjudgeProcesss = _LawjudgeProcess.GetAll().AsNoTracking().ToList();
   //             _cacheManager.GetCache("BaseDatasHelper").Set(key, LawjudgeProcesss, null, new TimeSpan(1, 0, 0, 0));
   //         }

            var LawjudgeProcesss = _LawjudgeProcess.GetAllIncluding(m => m.parentLawjudgeProcess, m => m.childLawjudgeProcess).ToList();

			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					return ((List<LawjudgeProcess>)LawjudgeProcesss).ToList();

				}
				else
				{
					return ((List<LawjudgeProcess>)LawjudgeProcesss).Where(p => p.levels == level).ToList();

				}

			}
			else
			{
				if (level == null)
				{
					return ((List<LawjudgeProcess>)LawjudgeProcesss).Where(p => p.name.Contains(name)).ToList();

				}
				else
				{
					return ((List<LawjudgeProcess>)LawjudgeProcesss).Where(p => p.name.Contains(name) && p.levels == level).ToList();
				}

			}
		}
		//[RemoteService(false)]
		//public List<LawjudgeProcess> ReturnNpidjudgeProcess(List<LawjudgeProcess> c)
		//{
		//	foreach (var item in c)
		//	{
		//		item.parentLawjudgeProcess = null;
		//		if (item.childLawjudgeProcess.Count > 0)
		//		{
		//			item.childLawjudgeProcess = ReturnNpidjudgeProcess(item.childLawjudgeProcess.ToList());
		//		}
		//	}
		//	return c;
		//}
		/// <summary>
		/// 第一级为审判类型，子集为审判流程
		/// </summary>
		/// <returns></returns>
		public List<LawjudgeProcess> GetjudgeProcessOUT(string name = null, int? level = null)
		{
            string key = "GetjudgeProcessOUT" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
            var LawjudgeProcesss = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
            if (LawjudgeProcesss == null)
            {
                //LawjudgeProcesss = _LawjudgeProcess.GetAllIncluding(m => m.parentLawjudgeProcess, m => m.childLawjudgeProcess).ToList();
                LawjudgeProcesss = _LawjudgeProcess.GetAll().AsNoTracking().ToList();
                _cacheManager.GetCache("BaseDatasHelper").Set(key, LawjudgeProcesss, null, new TimeSpan(1, 0, 0, 0));
            }
            //var LawjudgeProcesss = _LawjudgeProcess.GetAllIncluding(m => m.parentLawjudgeProcess, m => m.childLawjudgeProcess).ToList();
			List<LawjudgeProcess> CS = (List<LawjudgeProcess>)LawjudgeProcesss;
			
			List<LawjudgeProcess> re = new List<LawjudgeProcess>();
			LawjudgeProcess law;
			foreach (var item in CS)
			{
				law = new LawjudgeProcess() { Id = item.Id, levels = item.levels, name = item.name, pid = item.pid };
				item.childLawjudgeProcess = CS.Where(p => p.pid == item.Id).ToList();
				if (item.childLawjudgeProcess != null && item.childLawjudgeProcess.Count > 0)
				{
					foreach (var item2 in item.childLawjudgeProcess)
					{
						LawjudgeProcess law2 = new LawjudgeProcess() { Id = item2.Id, levels = item2.levels, name = item2.name, pid = item2.pid };
						item2.childLawjudgeProcess = CS.Where(p => p.pid == item2.Id).ToList();
						if (item2.childLawjudgeProcess != null && item2.childLawjudgeProcess.Count > 0)
						{
							foreach (var item3 in item2.childLawjudgeProcess)
							{
								LawjudgeProcess law3 = new LawjudgeProcess() { Id = item3.Id, levels = item3.levels, name = item3.name, pid = item3.pid };
								item3.childLawjudgeProcess = CS.Where(p => p.pid == item3.Id).ToList();
								if (item3.childLawjudgeProcess != null && item3.childLawjudgeProcess.Count > 0)
								{
									foreach (var item4 in item3.childLawjudgeProcess)
									{
										LawjudgeProcess law4 = new LawjudgeProcess() { Id = item4.Id, levels = item4.levels, name = item4.name, pid = item4.pid };
										item4.childLawjudgeProcess = CS.Where(p => p.pid == item4.Id).ToList();
										if (item4.childLawjudgeProcess != null && item4.childLawjudgeProcess.Count > 0)
										{
											foreach (var item5 in item4.childLawjudgeProcess)
											{
												LawjudgeProcess law5 = new LawjudgeProcess() { Id = item5.Id, levels = item5.levels, name = item5.name, pid = item5.pid };
												item5.childLawjudgeProcess = CS.Where(p => p.pid == item5.Id).ToList();
												if (item5.childLawjudgeProcess != null && item5.childLawjudgeProcess.Count > 0)
												{
													foreach (var item6 in item5.childLawjudgeProcess)
													{
														LawjudgeProcess law6 = new LawjudgeProcess() { Id = item6.Id, levels = item6.levels, name = item6.name, pid = item6.pid };
														item6.childLawjudgeProcess = CS.Where(p => p.pid == item6.Id).ToList();
														law5.childLawjudgeProcess.Add(law6);
													}
												}
												law4.childLawjudgeProcess.Add(law5);

											}
										}
										law3.childLawjudgeProcess.Add(law4);

									}
								}
								law2.childLawjudgeProcess.Add(law3);

							}
						}
						law.childLawjudgeProcess.Add(law2);

					}
				}
				re.Add(law);
			}
			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					re = re.ToList();

				}
				else
				{
					re = re.Where(p => p.levels == level).ToList();
				}
			}
			else
			{
				if (level == null)
				{
					re = re.Where(p => p.name != null && p.name.Contains(name)).ToList();

				}
				else
				{
					re = re.Where(p => p.name != null && p.name.Contains(name) && p.levels == level).ToList();
				}
			}
			return re;
		}


		/// <summary>
		/// 效力等级
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		[RemoteService(false)]
		public List<Laweff_level> GetLaweff_level(string name = null, int ? level = null)
		{
				//string key = "GetLaweff_level" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //        var Laweff_levels = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //        if (Laweff_levels == null)
    //        {
    //            //Laweff_levels = _Laweff_level.GetAllIncluding(m => m.parentLaweff_level, m => m.childLaweff_level).ToList();
    //            Laweff_levels = _Laweff_level.GetAll().ToList();
    //            _cacheManager.GetCache("BaseDatasHelper").Set(key, Laweff_levels, null, new TimeSpan(1, 0, 0, 0));
    //        }
            var Laweff_levels = _Laweff_level.GetAllIncluding(m => m.parentLaweff_level, m => m.childLaweff_level).ToList();
			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					return ((List<Laweff_level>)Laweff_levels).ToList();

				}
				else
				{
					return ((List<Laweff_level>)Laweff_levels).Where(p => p.levels == level).ToList();

				}

			}
			else
			{
				if (level == null)
				{
					return ((List<Laweff_level>)Laweff_levels).Where(p => p.name.Contains(name)).ToList();

				}
				else
				{
					return ((List<Laweff_level>)Laweff_levels).Where(p => p.name.Contains(name) && p.levels == level).ToList();
				}

			}
		}

		//[RemoteService(false)]
		//public List<Laweff_level> ReturnNpidLaweff_level(List<Laweff_level> c)
		//{
		//	foreach (var item in c)
		//	{
		//		item.parentLaweff_level = null;
		//		if (item.childLaweff_level.Count > 0)
		//		{
		//			item.childLaweff_level = ReturnNpidLaweff_level(item.childLaweff_level.ToList());
		//		}
		//	}
		//	return c;
		//}
		/// <summary>
		/// 效力等级
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		public List<Laweff_level> GetLaweff_levelOUT(string name = null, int ? level = null)
		{
				//string key = "GetLaweff_levelOUT" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //        var Laweff_levels = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //        if (Laweff_levels == null)
    //        {
    //            //Laweff_levels = _Laweff_level.GetAllIncluding(m => m.parentLaweff_level, m => m.childLaweff_level).ToList();
    //            Laweff_levels = _Laweff_level.GetAll().AsNoTracking().ToList();
    //            _cacheManager.GetCache("BaseDatasHelper").Set(key, Laweff_levels, null, new TimeSpan(1, 0, 0, 0));
    //        }
            var Laweff_levels = _Laweff_level.GetAllIncluding(m => m.parentLaweff_level, m => m.childLaweff_level).ToList();

			List<Laweff_level> CS = (List<Laweff_level>)Laweff_levels;
			
			List<Laweff_level> re = new List<Laweff_level>();
			Laweff_level law;
			foreach (var item in CS)
			{
				law = new Laweff_level() { Id = item.Id, levels = item.levels, name = item.name, pid = item.pid };
				if (item.childLaweff_level != null && item.childLaweff_level.Count > 0)
				{
					foreach (var item2 in item.childLaweff_level)
					{
						Laweff_level law2 = new Laweff_level() { Id = item2.Id, levels = item2.levels, name = item2.name, pid = item2.pid };
						if (item2.childLaweff_level != null && item2.childLaweff_level.Count > 0)
						{
							foreach (var item3 in item2.childLaweff_level)
							{
								Laweff_level law3 = new Laweff_level() { Id = item3.Id, levels = item3.levels, name = item3.name, pid = item3.pid };
								if (item3.childLaweff_level != null && item3.childLaweff_level.Count > 0)
								{
									foreach (var item4 in item3.childLaweff_level)
									{
										Laweff_level law4 = new Laweff_level() { Id = item4.Id, levels = item4.levels, name = item4.name, pid = item4.pid };
										if (item4.childLaweff_level != null && item4.childLaweff_level.Count > 0)
										{
											foreach (var item5 in item4.childLaweff_level)
											{
												Laweff_level law5 = new Laweff_level() { Id = item5.Id, levels = item5.levels, name = item5.name, pid = item5.pid };
												if (item5.childLaweff_level != null && item5.childLaweff_level.Count > 0)
												{
													foreach (var item6 in item5.childLaweff_level)
													{
														Laweff_level law6 = new Laweff_level() { Id = item6.Id, levels = item6.levels, name = item6.name, pid = item6.pid };
														law5.childLaweff_level.Add(law6);
													}
												}
												law4.childLaweff_level.Add(law5);

											}
										}
										law3.childLaweff_level.Add(law4);

									}
								}
								law2.childLaweff_level.Add(law3);

							}
						}
						law.childLaweff_level.Add(law2);

					}
				}
				re.Add(law);
			}
			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					re = re.ToList();

				}
				else
				{
					re = re.Where(p => p.levels == level).ToList();
				}
			}
			else
			{
				if (level == null)
				{
					re = re.Where(p => p.name != null && p.name.Contains(name)).ToList();

				}
				else
				{
					re = re.Where(p => p.name != null && p.name.Contains(name) && p.levels == level).ToList();
				}
			}
			return re;
		}


		/// <summary>
		/// 发布机关
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		[RemoteService(false)]
		public List<LawAuthority> GetLawAuthority(string name = null, int? level = null)
		{
				//string key = "GetLawAuthority" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //        var LawAuthoritys = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //        if (LawAuthoritys == null)
    //        {
    //            //LawAuthoritys = _LawAuthority.GetAllIncluding(m => m.parentLawAuthority, m => m.childLawAuthority).ToList();
    //            LawAuthoritys = _LawAuthority.GetAll().AsNoTracking().ToList();
    //            _cacheManager.GetCache("BaseDatasHelper").Set(key, LawAuthoritys, null, new TimeSpan(1, 0, 0, 0));
    //        }
            var LawAuthoritys = _LawAuthority.GetAllIncluding(m => m.parentLawAuthority, m => m.childLawAuthority).ToList();
			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					return ((List<LawAuthority>)LawAuthoritys).ToList();

				}
				else
				{
					return ((List<LawAuthority>)LawAuthoritys).Where(p => p.levels == level).ToList();

				}

			}
			else
			{
				if (level == null)
				{
					return ((List<LawAuthority>)LawAuthoritys).Where(p => p.name.Contains(name)).ToList();

				}
				else
				{
					return ((List<LawAuthority>)LawAuthoritys).Where(p => p.name.Contains(name) && p.levels == level).ToList();
				}

			}
		}
		//[RemoteService(false)]
		//public List<LawAuthority> ReturnNpidLawAuthority(List<LawAuthority> c)
		//{
		//	foreach (var item in c)
		//	{
		//		item.parentLawAuthority = null;
		//		if (item.childLawAuthority.Count > 0)
		//		{
		//			item.childLawAuthority = ReturnNpidLawAuthority(item.childLawAuthority.ToList());
		//		}
		//	}
		//	return c;
		//}
		/// <summary>
		/// 发布机关
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		public List<LawAuthority> GetLawAuthorityOUT(string name = null, int? level = null)
		{
				//string key = "GetLawAuthorityOUT" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //        var LawAuthoritys = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //        if (LawAuthoritys == null)
    //        {
    //            //LawAuthoritys = _LawAuthority.GetAllIncluding(m => m.parentLawAuthority, m => m.childLawAuthority).ToList();
    //            LawAuthoritys = _LawAuthority.GetAll().AsNoTracking().ToList();
    //            _cacheManager.GetCache("BaseDatasHelper").Set(key, LawAuthoritys, null, new TimeSpan(1, 0, 0, 0));
    //        }
            var LawAuthoritys = _LawAuthority.GetAllIncluding(m => m.parentLawAuthority, m => m.childLawAuthority).ToList();
			List<LawAuthority> CS = (List<LawAuthority>)LawAuthoritys;
			
			List<LawAuthority> re = new List<LawAuthority>();
			LawAuthority law;
			foreach (var item in CS)
			{
				law = new LawAuthority() { Id = item.Id, levels = item.levels, name = item.name, pid = item.pid };
				if (item.childLawAuthority != null && item.childLawAuthority.Count > 0)
				{
					foreach (var item2 in item.childLawAuthority)
					{
						LawAuthority law2 = new LawAuthority() { Id = item2.Id, levels = item2.levels, name = item2.name, pid = item2.pid };
						if (item2.childLawAuthority != null && item2.childLawAuthority.Count > 0)
						{
							foreach (var item3 in item2.childLawAuthority)
							{
								LawAuthority law3 = new LawAuthority() { Id = item3.Id, levels = item3.levels, name = item3.name, pid = item3.pid };
								if (item3.childLawAuthority != null && item3.childLawAuthority.Count > 0)
								{
									foreach (var item4 in item3.childLawAuthority)
									{
										LawAuthority law4 = new LawAuthority() { Id = item4.Id, levels = item4.levels, name = item4.name, pid = item4.pid };
										if (item4.childLawAuthority != null && item4.childLawAuthority.Count > 0)
										{
											foreach (var item5 in item4.childLawAuthority)
											{
												LawAuthority law5 = new LawAuthority() { Id = item5.Id, levels = item5.levels, name = item5.name, pid = item5.pid };
												if (item5.childLawAuthority != null && item5.childLawAuthority.Count > 0)
												{
													foreach (var item6 in item5.childLawAuthority)
													{
														LawAuthority law6 = new LawAuthority() { Id = item6.Id, levels = item6.levels, name = item6.name, pid = item6.pid };
														law5.childLawAuthority.Add(law6);
													}
												}
												law4.childLawAuthority.Add(law5);

											}
										}
										law3.childLawAuthority.Add(law4);

									}
								}
								law2.childLawAuthority.Add(law3);

							}
						}
						law.childLawAuthority.Add(law2);

					}
				}
				re.Add(law);
			}
			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					re = re.ToList();

				}
				else
				{
					re = re.Where(p => p.levels == level).ToList();
				}
			}
			else
			{
				if (level == null)
				{
					re = re.Where(p => p.name != null && p.name.Contains(name)).ToList();

				}
				else
				{
					re = re.Where(p => p.name != null && p.name.Contains(name) && p.levels == level).ToList();
				}
			}
			return re;
		}



		/// <summary>
		/// 主题分类
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		[RemoteService(false)]
		public List<LawType> GetLawType(string name = null, int? level = null)
		{
			//string key = "GetLawType" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
			//        var LawTypes = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
			//        if (LawTypes == null)
			//        {
			//            //LawTypes = _LawType.GetAllIncluding(m => m.parentLawType, m => m.childLawType).ToList();
			//            LawTypes = _LawType.GetAll().AsNoTracking().ToList();
			//            _cacheManager.GetCache("BaseDatasHelper").Set(key, LawTypes, null, new TimeSpan(1, 0, 0, 0));
			//        }
			var LawTypes = _LawType.GetAllIncluding(m => m.parentLawType, m => m.childLawType).ToList();

			if (string.IsNullOrEmpty(name))
            {
                if (level == null)
                {
					return ((List<LawType>)LawTypes).ToList();

				}
				else
                {
					return ((List<LawType>)LawTypes).Where(p => p.levels == level).ToList();

				}

			}
			else
            {
				if (level == null)
				{
					return ((List<LawType>)LawTypes).Where(p => p.name.Contains(name)).ToList();

				}
				else
				{
					return ((List<LawType>)LawTypes).Where(p => p.name.Contains(name) && p.levels == level).ToList();
				}

			}
		}
		//[RemoteService(false)]
		//public List<LawType> ReturnNpidLawType(List<LawType> c)
		//{
		//	foreach (var item in c)
		//	{
		//		item.parentLawType = null;
		//		if (item.childLawType.Count > 0)
		//		{
		//			item.childLawType = ReturnNpidLawType(item.childLawType.ToList());
		//		}
		//	}
		//	return c;
		//}
		/// <summary>
		/// 主题分类
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		public List<LawType> GetLawTypeOUT(string name = null, int ? level = null)
		{
				//string key = "GetLawTypeOUT" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //        var LawTypes = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //        if (LawTypes == null)
    //        {
    //            //LawTypes = _LawType.GetAllIncluding(m => m.parentLawType, m => m.childLawType).ToList();
    //            LawTypes = _LawType.GetAll().ToList();
    //            _cacheManager.GetCache("BaseDatasHelper").Set(key, LawTypes, null, new TimeSpan(1, 0, 0, 0));
    //        }
            var LawTypes = _LawType.GetAllIncluding(m => m.parentLawType, m => m.childLawType).ToList();
			List <LawType> CS = (List<LawType>)LawTypes;
			
			List<LawType> re = new List<LawType>();
			LawType law;
			foreach (var item in CS)
			{
				law = new LawType() { Id = item.Id, levels = item.levels, name = item.name, pid = item.pid };
				if (item.childLawType != null && item.childLawType.Count > 0)
				{
					foreach (var item2 in item.childLawType)
					{
						LawType law2 = new LawType() { Id = item2.Id, levels = item2.levels, name = item2.name, pid = item2.pid };
						if (item2.childLawType != null && item2.childLawType.Count > 0)
						{
							foreach (var item3 in item2.childLawType)
							{
								LawType law3 = new LawType() { Id = item3.Id, levels = item3.levels, name = item3.name, pid = item3.pid };
								if (item3.childLawType != null && item3.childLawType.Count > 0)
								{
									foreach (var item4 in item3.childLawType)
									{
										LawType law4 = new LawType() { Id = item4.Id, levels = item4.levels, name = item4.name, pid = item4.pid };
										if (item4.childLawType != null && item4.childLawType.Count > 0)
										{
											foreach (var item5 in item4.childLawType)
											{
												LawType law5 = new LawType() { Id = item5.Id, levels = item5.levels, name = item5.name, pid = item5.pid };
												if (item5.childLawType != null && item5.childLawType.Count > 0)
												{
													foreach (var item6 in item5.childLawType)
													{
														LawType law6 = new LawType() { Id = item6.Id, levels = item6.levels, name = item6.name, pid = item6.pid };
														law5.childLawType.Add(law6);
													}
												}
												law4.childLawType.Add(law5);

											}
										}
										law3.childLawType.Add(law4);

									}
								}
								law2.childLawType.Add(law3);

							}
						}
						law.childLawType.Add(law2);

					}
				}
				re.Add(law);
			}
			if (string.IsNullOrEmpty(name))
			{
				if (level == null)
				{
					re = re.ToList();

				}
				else
				{
					re = re.Where(p => p.levels == level).ToList();
				}
			}
			else
			{
				if (level == null)
				{
					re = re.Where(p => p.name != null && p.name.Contains(name)).ToList();

				}
				else
				{
					re = re.Where(p => p.name != null && p.name.Contains(name) && p.levels == level).ToList();
				}
			}
			return re;
		}


		/// <summary>
		/// 案由
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		[RemoteService(false)]
		public List<caseReason> GetcaseReason(string name = null, int ? level = null)
		{
            try
            {
				//string key = "GetcaseReason" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
    //            var caseReasons = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
    //            if (caseReasons == null)
    //            {
    //                //caseReasons = _caseReason.GetAllIncluding(m => m.parentCaseReason, m => m.childCasereasons).ToList();
    //                caseReasons = _caseReason.GetAll().AsNoTracking().ToList();
    //                _cacheManager.GetCache("BaseDatasHelper").Set(key, caseReasons, null, new TimeSpan(1, 0, 0, 0));
    //            }
				var caseReasons = _caseReason.GetAllIncluding(m => m.parentCaseReason, m => m.childCasereasons).ToList();
				if (string.IsNullOrEmpty(name))
				{
					if (level == null)
					{
						return ((List<caseReason>)caseReasons).ToList();

					}
					else
					{
						return ((List<caseReason>)caseReasons).Where(p => p.levels == level).ToList();
					}
				}
				else
				{
					if (level == null)
					{
						return ((List<caseReason>)caseReasons).Where(p => p.text.Contains(name)).ToList();

					}
					else
					{
						return ((List<caseReason>)caseReasons).Where(p => p.text.Contains(name) && p.levels == level).ToList();
					}
				}
			}
            catch (Exception ex)
            {

                throw;
            }

        }


		/// <summary>
		/// 案由
		/// </summary>
		/// <param name="level"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		public List<caseReason> GetcaseReasonOUT(string name = null, int? level = null)
        {
            try
            {
                string key = "GetcaseReasonOUT" + (name != null ? name.ToString() : "") + (level != null ? level.ToString() : "");
                var caseReasons = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
                if (caseReasons == null)
                {
                    //caseReasons = _caseReason.GetAllIncluding(m => m.parentCaseReason, m => m.childCasereasons).ToList();
                    caseReasons = _caseReason.GetAll().AsNoTracking().ToList();
                    _cacheManager.GetCache("BaseDatasHelper").Set(key, caseReasons, null, new TimeSpan(1, 0, 0, 0));
                }
                //var caseReasons = _caseReason.GetAllIncluding(m => m.parentCaseReason, m => m.childCasereasons).ToList();
                List<caseReason> CS = (List<caseReason>)caseReasons;
				CS.ForEach(cr => cr.text = cr.text.Contains("-") ? cr.text : cr.text + "-" + cr.Id);
				
				List<caseReason> re = new List<caseReason>();
				caseReason law;
				foreach (var item in CS)
				{
					law = new caseReason() { Id = item.Id, levels = item.levels, text = item.text,  parent = item.parent };
					item.childCasereasons = CS.Where(p => p.parent == item.Id).ToList();
					if (item.childCasereasons != null && item.childCasereasons.Count > 0)
					{
						foreach (var item2 in item.childCasereasons)
						{
							caseReason law2 = new caseReason() { Id = item2.Id, levels = item2.levels, text = item2.text, parent = item2.parent };
							item2.childCasereasons = CS.Where(p => p.parent == item2.Id).ToList();
							if (item2.childCasereasons != null && item2.childCasereasons.Count > 0)
							{
								foreach (var item3 in item2.childCasereasons)
								{
									caseReason law3 = new caseReason() { Id = item3.Id, levels = item3.levels, text = item3.text, parent = item3.parent };
									item3.childCasereasons = CS.Where(p => p.parent == item3.Id).ToList();
									if (item3.childCasereasons != null && item3.childCasereasons.Count > 0)
									{
										foreach (var item4 in item3.childCasereasons)
										{
											caseReason law4 = new caseReason() { Id = item4.Id, levels = item4.levels, text = item4.text, parent = item4.parent };
											item4.childCasereasons = CS.Where(p => p.parent == item4.Id).ToList();
											if (item4.childCasereasons != null && item4.childCasereasons.Count > 0)
											{
												foreach (var item5 in item4.childCasereasons)
												{
													caseReason law5 = new caseReason() { Id = item5.Id, levels = item5.levels, text = item5.text, parent = item5.parent };
													item5.childCasereasons = CS.Where(p => p.parent == item5.Id).ToList();
													if (item5.childCasereasons != null && item5.childCasereasons.Count > 0)
													{
														foreach (var item6 in item5.childCasereasons)
														{
															caseReason law6 = new caseReason() { Id = item6.Id, levels = item6.levels, text = item6.text, parent = item6.parent };
															item6.childCasereasons = CS.Where(p => p.parent == item6.Id).ToList();
															law5.childCasereasons.Add(law6);
														}
													}
													law4.childCasereasons.Add(law5);

												}
											}
											law3.childCasereasons.Add(law4);

										}
									}
									law2.childCasereasons.Add(law3);

								}
							}
							law.childCasereasons.Add(law2);

						}
					}
					re.Add(law);
				}
				if (string.IsNullOrEmpty(name))
				{
					if (level == null)
					{
						re = re.ToList();

					}
					else
					{
						re = re.Where(p => p.levels == level).ToList();
					}
				}
				else
				{
					if (level == null)
					{
						re = re.Where(p => p.text != null && p.text.Contains(name)).ToList();

					}
					else
					{
						re = re.Where(p => p.text != null && p.text.Contains(name) && p.levels == level).ToList();
					}
				}
				return re;

			}
            catch (Exception ex)
            {

                throw;
            }
        }

		//[RemoteService(false)]
		//public List<caseReason> ReturnNpid(List<caseReason> c)
		//{
		//    foreach (var item in c)
		//    {
		//        item.parentCaseReason = null;
		//        if (item.childCasereasons.Count > 0)
		//        {
		//            item.childCasereasons = ReturnNpid(item.childCasereasons.ToList());
		//        }
		//    }
		//    return c;
		//}

		/// <summary>
		/// 时效性 out
		/// </summary>
		/// <returns></returns>
		public List<string> Gettime_limited(string name = "")
		{
			 
			List<string> time_limited = new List<string>();
			time_limited.Add("现行有效");
			time_limited.Add("失效");
			time_limited.Add("已被修改");
			time_limited.Add("尚未生效");
			time_limited.Add("部分失效");
			time_limited.Add("实际失效");

			if (string.IsNullOrEmpty(name))
			{
				return (List<string>)time_limited;

			}
			else
			{
				return ((List<string>)time_limited).Where(p => p.Contains(name)).ToList();

			}
		}
		/// <summary>
		/// 获取法律法规地区
		/// </summary>
		/// <returns></returns>
		public List<string> GetLawArea(string name = "")
		{
			List<string> lists = new List<string>();
			lists.Add("北京市");
			lists.Add("河北省");
			lists.Add("天津市");
			lists.Add("山西省");
			lists.Add("内蒙古自治区");
			lists.Add("辽宁省");
			lists.Add("吉林省");
			lists.Add("黑龙江省");
			lists.Add("上海市");
			lists.Add("江苏省");
			lists.Add("浙江省");
			lists.Add("安徽省");
			lists.Add("福建省");
			lists.Add("江西省");
			lists.Add("山东省");
			lists.Add("河南省");
			lists.Add("湖南省");
			lists.Add("湖北省");
			lists.Add("广东省");
			lists.Add("广西壮族自治区");
			lists.Add("四川省");
			lists.Add("贵州省");
			lists.Add("云南省");
			lists.Add("西藏自治区");
			lists.Add("陕西省");
			lists.Add("甘肃省");
			lists.Add("青海省");
			lists.Add("宁夏回族自治区");
			lists.Add("新疆维吾尔自治区");
			lists.Add("海南省");
			lists.Add("重庆市");

			if (string.IsNullOrEmpty(name))
            {
				return (List<string>)lists;

			}
            else
            {
				return ((List<string>)lists).Where(p=>p.Contains(name)).ToList();

			}
		}
	
		/// <summary>
		/// 审判结果
		/// </summary>
		/// <returns></returns>
		public List<string> getjudgeResuls(string name = "")
		{
			List<string> lists = new List<string>();
			lists.Add("终结本次执行程序");
			lists.Add("财产执行");
			lists.Add("终结执行");
			lists.Add("执行完毕");
			lists.Add("纳入失信被执行人名单");
			lists.Add("中止执行");
			lists.Add("撤回申请");
			lists.Add("撤销申请");
			lists.Add("指定/提级执行");
			lists.Add("追加/变更执行人");
			lists.Add("移送管辖");
			lists.Add("解除财产执行");
			lists.Add("责令履行");
			lists.Add("维持原判");
			lists.Add("撤回起诉");
			lists.Add("驳回申请");
			lists.Add("部分支持");
			lists.Add("全部支持");
			lists.Add("其他");
			lists.Add("不予执行");
			lists.Add("销案");
			lists.Add("不予立案（原不予受理）");
			lists.Add("不予登记立案");
			lists.Add("裁定终结本次执行程序");
			lists.Add("保全完毕");
			lists.Add("部分保全");
			lists.Add("无标的物可实施保全");
			lists.Add("解除保全");
			lists.Add("其他部门撤回");
			lists.Add("准予撤回异议或申请");
			lists.Add("驳回异议或申请");
			lists.Add("异议成立并撤销相关执行行为、中止对执行标的的执行、不予执行、追加变更当事人");
			lists.Add("异议部分成立并部分撤销并变更执行行为、部分不予执行、部分追加变更当事人");
			lists.Add("异议成立或部分成立但不撤销、变更执行行为");
			lists.Add("终结审查");
			lists.Add("不予受理");
			lists.Add("指令下一级法院立案");
			lists.Add("指令下一级法院审查");
			lists.Add("裁定撤销执行案件");
			lists.Add("维持");
			lists.Add("变更原裁定");
			lists.Add("撤销原决定");
			lists.Add("变更原决定");
			lists.Add("撤销原裁定并裁定中止对执行标的的执行");
			lists.Add("撤销原裁定并撤销执行行为");
			lists.Add("撤销原裁定并裁定继续执行");
			lists.Add("撤销原裁定并裁定不予执行");
			lists.Add("撤销原裁定并裁定不予追加变更当事人");
			lists.Add("撤销原裁定并裁定追加变更当事人");
			lists.Add("裁定发回重新审查");
			lists.Add("准予撤回申请");
			lists.Add("纠正原处理意见");
			lists.Add("督促按原处理意见办理");
			lists.Add("准许撤回监督申请");
			lists.Add("驳回监督申请");
			lists.Add("责令执行法院限期改正");
			lists.Add("撤销执行法院裁定并直接改正");
			lists.Add("本院提级执行");
			lists.Add("指定其他法院执行");
			lists.Add("对不予执行申请直接作出裁定");
			lists.Add("指令重新审查");
			lists.Add("撤回协调请求");
			lists.Add("协调解决（即达成一致意见）");
			lists.Add("协调不成报请上级处理");
			lists.Add("指定原执行法院管辖");
			lists.Add("直接作出决定或裁定");
			lists.Add("裁定本院提级执行");
			lists.Add("不同意报请法院处理意见");
			lists.Add("同意报请法院处理意见");
			lists.Add("变更报请法院处理意见");
			lists.Add("撤回请求");
			lists.Add("本院提级管辖（含同意下级法院移送本院）");
			lists.Add("本院不同意提级管辖（含不同意下级法院移送本院）");
			lists.Add("本院指定其他法院管辖");
			lists.Add("本院指定报请法院管辖");
			lists.Add("商定由对方下级法院管辖");
			lists.Add("商定由本院下级法院管辖");
			lists.Add("协商不成并报请最高院指定");
			lists.Add("维持原裁定");
			lists.Add("撤销原裁定并裁定移送其他法院管辖");
			lists.Add("撤销原裁定并驳回管辖异议");
			lists.Add("准予撤回上诉");
			lists.Add("按撤回上诉处理");
			lists.Add("终结");
			lists.Add("不予立案");
			lists.Add("驳回起诉");
			lists.Add("准予撤诉");
			lists.Add("按撤诉处理");
			lists.Add("调解");
			lists.Add("裁定移送其他法院管辖");
			lists.Add("被上级法院提级管辖");
			lists.Add("被指定其他法院管辖");
			lists.Add("与本院其他案件并案审理");
			lists.Add("指定其他下级法院立案审理");
			lists.Add("改判");
			lists.Add("发回重审");
			lists.Add("撤销原判并驳回起诉");
			lists.Add("撤销原裁定并指令受理");
			lists.Add("撤销原裁定并指令审理");
			lists.Add("撤销原判并裁定移送其他法院管辖");
			lists.Add("本院再审");
			lists.Add("本院提审");
			lists.Add("指令原审法院再审");
			lists.Add("指定其他法院再审");
			lists.Add("裁定驳回再审申请");
			lists.Add("准予撤回再审申请");
			lists.Add("按撤回再审申请处理");
			lists.Add("准予撤回抗诉");
			lists.Add("撤销原裁判并裁定移送");
			lists.Add("撤销原裁定并恢复二审程序");
			lists.Add("决定赔偿（含部分赔偿）");
			lists.Add("决定不予赔偿");
			lists.Add("不予立案（即不予受理）");
			lists.Add("决定驳回申请（程序性驳回）");
			lists.Add("按撤回申请处理");
			lists.Add("维持原决定");
			lists.Add("撤销原决定并决定赔偿");
			lists.Add("决定赔偿");
			lists.Add("根据赔偿协议制作决定并撤销原决定");
			lists.Add("撤销原决定并驳回申请");
			lists.Add("决定驳回申请");
			lists.Add("决定不予立案");
			lists.Add("撤销原决定并指令复议机关作出决定");
			lists.Add("撤销原决定并指令赔偿义务法院作出决定");
			lists.Add("驳回申诉");
			lists.Add("指令下级法院受理");
			lists.Add("本院决定重新审理");
			lists.Add("指令重新审理");
			lists.Add("本院决定直接审理");
			lists.Add("准许撤回申诉");
			lists.Add("按撤回申诉处理");
			lists.Add("确认违法");
			lists.Add("裁定准予强制执行");
			lists.Add("裁定不准予强制执行");
			lists.Add("撤销原裁定并裁定准予强制执行");
			lists.Add("撤销原裁定并裁定不准予强制执行");
			lists.Add("变更原裁定（即部分准予强制执行）");
			lists.Add("发回重新审查");
			lists.Add("准予撤回复议申请");
			lists.Add("按撤回复议申请处理");
			lists.Add("批准下交审理");
			lists.Add("不批准下交审理");
			lists.Add("裁定下级法院将案件移送有管辖权法院审理");
			lists.Add("撤销原判并裁定移送有管辖权法院审理");
			lists.Add("决定不予再审");
			lists.Add("撤销原生效判决、裁定、调解");
			lists.Add("仅撤销原生效判决、裁定、调解的错误部分");
			lists.Add("仅变更原生效判决、裁定、调解的错误部分");
			lists.Add("驳回诉讼请求");
			lists.Add("并入再审案件审理");
			lists.Add("判决变更选举委员会决定");
			lists.Add("终结程序");
			lists.Add("判决宣告失踪");
			lists.Add("判决宣告死亡");
			lists.Add("判决撤销失踪宣告");
			lists.Add("判决撤销死亡宣告");
			lists.Add("判决驳回申请");
			lists.Add("裁定另行指定财产代管人");
			lists.Add("裁定驳回申请");
			lists.Add("判决认定无民事行为能力");
			lists.Add("判决认定限制民事行为能力");
			lists.Add("撤销原判决并认定无民事行为能力");
			lists.Add("撤销原判决并认定限制民事行为能力");
			lists.Add("撤销无民事行为能力认定");
			lists.Add("撤销限制民事行为能力认定");
			lists.Add("裁定驳回异议");
			lists.Add("判决撤销指定");
			lists.Add("准予撤回异议");
			lists.Add("按撤回异议处理");
			lists.Add("判决变更监护关系");
			lists.Add("判决收归国有");
			lists.Add("判决收归集体所有");
			lists.Add("撤销财产无主认定并判决财产归属");
			lists.Add("裁定准予拍卖或变卖担保财产");
			lists.Add("确认协议有效");
			lists.Add("裁定移送其他法院");
			lists.Add("设立海事赔偿责任限制基金");
			lists.Add("受偿分配完毕");
			lists.Add("终结债权登记与受偿程序");
			lists.Add("撤销或部分撤销仲裁裁决");
			lists.Add("认定仲裁协议有效");
			lists.Add("认定仲裁协议无效");
			lists.Add("驳回异议");
			lists.Add("作出新判决");
			lists.Add("撤销原裁判");
			lists.Add("变更原裁判");
			lists.Add("不准予申请");
			lists.Add("作出除权判决");
			lists.Add("终结催告程序");
			lists.Add("支付令生效");
			lists.Add("撤销支付令");
			lists.Add("驳回当事人请求");
			lists.Add("终结强制清算程序");
			lists.Add("终结破产程序");
			lists.Add("作出人身安全保护令");
			lists.Add("驳回人身安全保护令申请");
			lists.Add("撤销人身安全保护令");
			lists.Add("变更人身安全保护令");
			lists.Add("延长人身安全保护令");
			lists.Add("指令其他法院再审");
			lists.Add("终止");
			lists.Add("准予撤回申诉");
			lists.Add("通知不予重新审判");
			lists.Add("层报上级法院审查");
			lists.Add("退回检察院");
			lists.Add("裁定驳回全部申请");
			lists.Add("裁定没收违法所得财产（支持全部申请）");
			lists.Add("裁定没收违法所得财产（支持部分申请）");
			lists.Add("终止审理");
			lists.Add("裁定核准");
			lists.Add("改判（含部分核准）");
			lists.Add("报请最高院核准");
			lists.Add("本院按二审程序提审");
			lists.Add("指定其他法院重审");
			lists.Add("撤销原假释裁定");
			lists.Add("作出强制医疗决定");
			lists.Add("驳回强制医疗申请");
			lists.Add("解除强制医疗决定");
			lists.Add("决定继续强制医疗");
			lists.Add("准予撤回监督意见");
			lists.Add("裁定停止执行死刑");
			lists.Add("决定继续执行死刑");
			lists.Add("调查核实停止执行死刑事由存在");
			lists.Add("调查核实停止执行死刑事由不存在");
			lists.Add("裁定继续执行死刑");
			lists.Add("准许减免罚金");
			lists.Add("驳回减免罚金申请");
			lists.Add("决定收监执行");
			lists.Add("裁定减刑");
			lists.Add("裁定不予减刑");
			lists.Add("裁定假释");
			lists.Add("裁定不予假释");
			lists.Add("准予撤回减刑、假释建议");
			lists.Add("撤销缓刑");
			lists.Add("撤销假释");
			lists.Add("决定暂予监外执行");
			lists.Add("维持原裁（决）定");
			lists.Add("撤销原裁（决）定");
			lists.Add("变更原裁（决）定");
			lists.Add("检察院撤回监督意见");
			lists.Add("指令原审法院重新审查");
			lists.Add("予以备案");
			lists.Add("同意并报请上级法院审查");
			lists.Add("责令依法纠正");

			if (string.IsNullOrEmpty(name))
            {
				return (List<string>)lists;

			}
            else
            {
				return ((List<string>)lists).Where(p=>p.Contains(name)).ToList();

			}
		}

		/// <summary>
		/// 法院等级
		/// </summary>
		/// <returns></returns>
		public List<string> getcourtLevel()
		{
			List<string> lists = new List<string>();
			lists.Add("最高法院");
			lists.Add("高级法院");
			lists.Add("中级法院");
			lists.Add("基层法院");
			return (List<string>)lists;
		}
		

		
		/// <summary>
		/// 获取行业
		/// </summary>
		/// <returns></returns>
		public List<string> getindustry()
		{
			List<string> lists = new List<string>();
			lists.Add("农、林、牧、渔业");
			lists.Add("采矿业");
			lists.Add("制造业");
			lists.Add("电力、热力、燃气及水生产和供应业");
			lists.Add("建筑业");
			lists.Add("批发和零售业");
			lists.Add("交通运输、仓储和邮政业");
			lists.Add("住宿和餐饮业");
			lists.Add("信息传输、软件和信息技术服务业");
			lists.Add("金融业");
			lists.Add("房地产业");
			lists.Add("租赁和商务服务业");
			lists.Add("科学研究和技术服务业");
			lists.Add("水利、环境和公共设施管理业");
			lists.Add("居民服务、修理和其他服务业");
			lists.Add("教育");
			lists.Add("卫生和社会工作");
			lists.Add("文化、体育和娱乐业");
			lists.Add("公共管理、社会保障和社会组织");
			lists.Add("国际组织");
			return (List<string>)lists;
		}

		/// <summary>
		/// 获取文书类型
		/// </summary>
		/// <returns></returns>
		public  List<docType> GetdocType()
		{
			List<docType> lists = new List<docType>();
			lists.Add(new docType()
			{
				code = "01",
				name = "判决书"
			});
			lists.Add(new docType()
			{
				code = "02",
				name = "裁定书"
			});
			lists.Add(new docType()
			{
				code = "03",
				name = "调解书"
			});
			lists.Add(new docType()
			{
				code = "04",
				name = "决定书"
			});
			lists.Add(new docType()
			{
				code = "05",
				name = "通知书"
			});
			lists.Add(new docType()
			{
				code = "09",
				name = "令"
			});
			lists.Add(new docType()
			{
				code = "10",
				name = "其他"
			});
			return (List<docType>)lists;
		}

		/// <summary>
		/// 获取地区 裁判文书
		/// </summary>
		/// <returns></returns>
		public  List<region> Getregion(string name = "")
		{
			List<region> lists = new List<region>();
			lists.Add(new region()
			{
				dataValue = "最高人民法院",
				fyCode = "0"
			});
			lists.Add(new region()
			{
				dataValue = "北京市",
				fyCode = "100"
			});
			lists.Add(new region()
			{
				dataValue = "天津市",
				fyCode = "200"
			});
			lists.Add(new region()
			{
				dataValue = "河北省",
				fyCode = "300"
			});
			lists.Add(new region()
			{
				dataValue = "山西省",
				fyCode = "400"
			});
			lists.Add(new region()
			{
				dataValue = "内蒙古自治区",
				fyCode = "500"
			});
			lists.Add(new region()
			{
				dataValue = "辽宁省",
				fyCode = "600"
			});
			lists.Add(new region()
			{
				dataValue = "吉林省",
				fyCode = "700"
			});
			lists.Add(new region()
			{
				dataValue = "黑龙江省",
				fyCode = "800"
			});
			lists.Add(new region()
			{
				dataValue = "上海市",
				fyCode = "900"
			});
			lists.Add(new region()
			{
				dataValue = "江苏省",
				fyCode = "A00"
			});
			lists.Add(new region()
			{
				dataValue = "浙江省",
				fyCode = "B00"
			});
			lists.Add(new region()
			{
				dataValue = "安徽省",
				fyCode = "C00"
			});
			lists.Add(new region()
			{
				dataValue = "福建省",
				fyCode = "D00"
			});
			lists.Add(new region()
			{
				dataValue = "江西省",
				fyCode = "E00"
			});
			lists.Add(new region()
			{
				dataValue = "山东省",
				fyCode = "F00"
			});
			lists.Add(new region()
			{
				dataValue = "河南省",
				fyCode = "G00"
			});
			lists.Add(new region()
			{
				dataValue = "湖北省",
				fyCode = "H00"
			});
			lists.Add(new region()
			{
				dataValue = "湖南省",
				fyCode = "I00"
			});
			lists.Add(new region()
			{
				dataValue = "广东省",
				fyCode = "J00"
			});
			lists.Add(new region()
			{
				dataValue = "广西壮族自治区",
				fyCode = "K00"
			});
			lists.Add(new region()
			{
				dataValue = "海南省",
				fyCode = "L00"
			});
			lists.Add(new region()
			{
				dataValue = "重庆市",
				fyCode = "M00"
			});
			lists.Add(new region()
			{
				dataValue = "四川省",
				fyCode = "N00"
			});
			lists.Add(new region()
			{
				dataValue = "贵州省",
				fyCode = "O00"
			});
			lists.Add(new region()
			{
				dataValue = "云南省",
				fyCode = "P00"
			});
			lists.Add(new region()
			{
				dataValue = "西藏自治区",
				fyCode = "Q00"
			});
			lists.Add(new region()
			{
				dataValue = "陕西省",
				fyCode = "R00"
			});
			lists.Add(new region()
			{
				dataValue = "甘肃省",
				fyCode = "S00"
			});
			lists.Add(new region()
			{
				dataValue = "青海省",
				fyCode = "T00"
			});
			lists.Add(new region()
			{
				dataValue = "宁夏回族自治区",
				fyCode = "U00"
			});
			lists.Add(new region()
			{
				dataValue = "新疆维吾尔自治区",
				fyCode = "V00"
			});
			lists.Add(new region()
			{
				dataValue = "新疆维吾尔自治区高级人民法院生产建设兵团分院",
				fyCode = "X00"
			});
			if (string.IsNullOrEmpty(name))
            {
				return (List<region>)lists;

			}
            else
            {
				return ((List<region>)lists).Where(p => p.dataValue.Contains(name)).ToList();
				
			}
		}


		/// <summary>
		/// 获取法院名称  模糊搜索
		/// </summary>
		/// <param name="name"></param>
		/// <param name="top"></param>
		/// <returns></returns>
		public List<courtFullName> GetcourtFullName(string name= "", string region = "", int top = 10)
		{
			string key = "GetcourtFullName" + name + region + top.ToString();

            var courtFullName = _cacheManager.GetCache("BaseDatasHelper").GetOrDefault(key);
            if (courtFullName == null)
            {
                courtFullName = _courtFullName.GetAll().AsNoTracking().ToList();
                _cacheManager.GetCache("BaseDatasHelper").Set(key, courtFullName, null, new TimeSpan(1, 0, 0, 0));

            }

            //var courtFullName = _courtFullName.GetAll().AsNoTracking().ToList();
			if (!string.IsNullOrEmpty(name) && string.IsNullOrEmpty(region))
			{
				return ((List<courtFullName>)courtFullName).Where(p => p.name.Contains(name)).Take(top).ToList();
			}
			else if (!string.IsNullOrEmpty(region) && string.IsNullOrEmpty(name))
			{
				return ((List<courtFullName>)courtFullName).Where(p => p.region != null &&  p.region.Contains(region)).Take(top).ToList();
			}
            else if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(region))
            {
				return ((List<courtFullName>)courtFullName).Where(p => p.region != null && p.region.Contains(region) && p.name.Contains(name)).Take(top).ToList();
			}
            if (top == 0)
            {
				return ((List<courtFullName>)courtFullName).ToList();
			}
            else
            {
				return ((List<courtFullName>)courtFullName).Take(top).ToList();
			}
		}

		/// <summary>
		/// 判决刑法
		/// </summary>
		/// <returns></returns>
		public List<string> getcriminalLaws()
		{
			List<string> proofs = new List<string>();
			//proofs.Add("主刑");
			proofs.Add("管制");
			proofs.Add("拘役");
			proofs.Add("有期徒刑");
			proofs.Add("无期徒刑");
			proofs.Add("死刑");
			proofs.Add("死刑立即执行");
			proofs.Add("死刑缓期执行");
			proofs.Add("不适用死刑");

			//proofs.Add("附加刑");
			proofs.Add("罚金");
			proofs.Add("并处罚金");
			proofs.Add("单处罚金");
			proofs.Add("剥夺政治权利");
			proofs.Add("没收财产");
			proofs.Add("驱逐出境");

			proofs.Add("免于刑事处罚");
			return proofs;
		}

		/// <summary>
		/// 证据类型
		/// </summary>
		/// <returns></returns>
		public  List<string> getproofs()
		{
			List<string> proofs = new List<string>();

			proofs.Add("直接证据");
			proofs.Add("间接证据");
			proofs.Add("言词证据");
			proofs.Add("实物证据");
			proofs.Add("原始证据");
			proofs.Add("传来证据");
			proofs.Add("有罪证据");
			proofs.Add("无罪证据");
			proofs.Add("材料");
			proofs.Add("被害人陈述");
			proofs.Add("辩解");
			proofs.Add("供述");
			proofs.Add("鉴定意见");
			proofs.Add("检查");
			proofs.Add("辨认");
			proofs.Add("侦查");
			proofs.Add("实验");
			proofs.Add("数据");
			proofs.Add("电子");
			proofs.Add("电子数据");
			proofs.Add("书证");
			proofs.Add("资料");
			proofs.Add("物证");
			proofs.Add("鉴定");
			proofs.Add("勘验笔录");
			proofs.Add("现场笔录");
			proofs.Add("合同");
			proofs.Add("收条");
			proofs.Add("单据");
			proofs.Add("收据");
			proofs.Add("票据");
			proofs.Add("协议书");
			proofs.Add("公证书");
			proofs.Add("照片");
			proofs.Add("笔录");
			proofs.Add("陈述");
			proofs.Add("当事人陈述");
			proofs.Add("当庭陈述");
			proofs.Add("视频");
			proofs.Add("聊天记录");
			proofs.Add("邮件");
			proofs.Add("证人");
			proofs.Add("证言");
			proofs.Add("勘验");
			proofs.Add("录音");
			proofs.Add("短信");
			return proofs;
		}

		/// <summary>
		/// 案件特征
		/// </summary>
		/// <returns></returns>
		public  List<string> getFeatures(string name = "")
		{
			List<string> features = new List<string>();
			features.Add("民间借贷");
			features.Add("借款金额");
			features.Add("违约金");
			features.Add("从轻处罚");
			features.Add("赔偿损失");
			features.Add("坦白");
			features.Add("借贷关系证据");
			features.Add("还款责任");
			features.Add("有期徒刑");
			features.Add("多个借款人");
			features.Add("违约责任");
			features.Add("金融机构");
			features.Add("医疗费");
			features.Add("未按期返还借款");
			features.Add("人身损害");
			features.Add("交通费");
			features.Add("减刑");
			features.Add("独任审判");
			features.Add("护理费");
			features.Add("误工费");
			features.Add("多辆机动车致人损害");
			features.Add("机动车致人损害");
			features.Add("未约定利息");
			features.Add("保证");
			features.Add("住院伙食");
			features.Add("补助费");
			features.Add("物业服务合同");
			features.Add("营养费");
			features.Add("鉴定费");
			features.Add("受害人住院");
			features.Add("自愿认罪");
			features.Add("认罪认罚");
			features.Add("物业服务");
			features.Add("利息约定不明");
			features.Add("连带保证");
			features.Add("债务承担");
			features.Add("残疾赔偿");
			features.Add("劳动报酬");
			features.Add("驾驶机动车");
			features.Add("缓刑");
			features.Add("担保责任");
			features.Add("年利率24");
			features.Add("逾期罚息");
			features.Add("复利");
			features.Add("精神抚慰金");
			features.Add("退赃");
			features.Add("退赔");
			features.Add("保险公司");
			features.Add("垫付");
			features.Add("商业险");
			features.Add("悔罪");
			features.Add("自首");
			features.Add("交强险");
			features.Add("伤残");
			features.Add("从重处罚");
			features.Add("网络借贷平台");
			features.Add("借贷关系");
			features.Add("现金");
			features.Add("取得谅解");
			features.Add("精神损害");
			features.Add("利息");
			features.Add("保证期间");
			features.Add("精神损害抚慰金");
			features.Add("约定借款期限");
			features.Add("返还借款本息");
			features.Add("限制行为能力");
			features.Add("子女抚养");
			features.Add("行政法规");
			features.Add("强制性规定");
			features.Add("逾期利率");
			features.Add("透支");
			features.Add("前科");
			features.Add("房产");
			features.Add("罚金");
			features.Add("感情破裂");
			features.Add("调解无效");
			features.Add("夫妻关系");
			features.Add("劳动关系");
			features.Add("假释");
			features.Add("车辆所有人");
			features.Add("房屋租赁");
			features.Add("连带保证责任");
			features.Add("亲属关系");
			features.Add("朋友关系");
			features.Add("逾期利息");
			features.Add("银行转账");
			features.Add("夫妻共同债务");
			features.Add("健康权");
			features.Add("剥夺政治权利");
			features.Add("数额大");
			features.Add("个人");
			features.Add("合同有效");
			features.Add("合同无效");
			features.Add("累犯");
			features.Add("租赁期限");
			features.Add("租金");
			features.Add("支付期限");
			features.Add("租赁物");
			features.Add("约定借款期限");
			features.Add("贪污");
			features.Add("全部责任");
			features.Add("仲裁申请");
			features.Add("共同犯罪");
			features.Add("未及时支付");
			features.Add("民政行政处罚");
			features.Add("抚养费");
			features.Add("主动赔偿");
			features.Add("健康权");
			features.Add("醉酒驾驶");
			features.Add("债权人");
			features.Add("连带责任");
			features.Add("毒品");
            if (string.IsNullOrEmpty(name))
            {
				return features;

			}
            else
            {
				return features.Where(p => p.Contains(name)).ToList(); 
			}
		}
		/// <summary>
		/// 案件焦点
		/// </summary>
		/// <returns></returns>
		public  List<string> getfocuss(string name = "")
		{
			List<string> focuss = new List<string>();
			focuss.Add("合同");
			focuss.Add("违约金");
			focuss.Add("医疗费用认定");
			focuss.Add("共同犯罪");
			focuss.Add("误工费");
			focuss.Add("借款利息");
			focuss.Add("减轻处罚");
			focuss.Add("借款数额");
			focuss.Add("附带民事赔偿");
			focuss.Add("保险");
			focuss.Add("利息");
			focuss.Add("违约");
			focuss.Add("证据");
			focuss.Add("劳动合同解除");
			focuss.Add("量刑");
			focuss.Add("罪与非罪");
			focuss.Add("劳动补偿金");
			focuss.Add("担保责任");
			focuss.Add("赔偿费用");
			focuss.Add("责任份额承担");
			focuss.Add("鉴定结论");
			focuss.Add("离婚");
			focuss.Add("利率");
			focuss.Add("赔偿数额");
			focuss.Add("滞纳金");
			focuss.Add("赔偿范围");
			focuss.Add("主体资格");
			focuss.Add("感情破裂");
			focuss.Add("性质认定");
			focuss.Add("违约行为");
			focuss.Add("被侵权人过错");
			focuss.Add("加班");
			focuss.Add("伤残");
			focuss.Add("工程款");
			focuss.Add("医疗费用");
			focuss.Add("逾期交房");
			focuss.Add("物业费");
			focuss.Add("诉讼时效适用");
			focuss.Add("实际借款金额");
			focuss.Add("夫妻共同债务");
			focuss.Add("程序");
			focuss.Add("垫付款");
			focuss.Add("抵押");
			focuss.Add("房屋租金");
			focuss.Add("费用范围");
			focuss.Add("欠款");
			focuss.Add("诉讼时效");
			focuss.Add("抚养权");
			focuss.Add("节假日");
			focuss.Add("劳动纠纷解决");
			focuss.Add("房产份额是否应当纳入可分配财产的范围");
			focuss.Add("劳动合同成立");
			focuss.Add("担保人");
			focuss.Add("定金");
			focuss.Add("货物交付");
			focuss.Add("房产");
			focuss.Add("支付");
			focuss.Add("借款协议效力");
			focuss.Add("责任承担");
			focuss.Add("工龄");
			focuss.Add("工伤");
			focuss.Add("精神损害赔偿");
			focuss.Add("不可抗力");
			focuss.Add("费用");
			focuss.Add("因果关系");
			focuss.Add("保证金");
			focuss.Add("护理费");
			focuss.Add("连带清偿责任");
			focuss.Add("侵权责任");
			focuss.Add("保险事故情况");
			focuss.Add("法律关系");
			focuss.Add("解除权");
			focuss.Add("交通费");
			focuss.Add("房屋质量");
			focuss.Add("债务");
			focuss.Add("免责");
			focuss.Add("股东资格");
			focuss.Add("婚姻关系");
			focuss.Add("合同关系");
			focuss.Add("抚养费");
			focuss.Add("股权转让协议");
			focuss.Add("财产分割");
			focuss.Add("最低工资标准");
			focuss.Add("过错责任");
			focuss.Add("赔偿损失");
			focuss.Add("退休");
			focuss.Add("租赁协议效力");
			focuss.Add("手续费");
			focuss.Add("合同解除");
			focuss.Add("刑讯逼供");
			focuss.Add("彩礼");
			focuss.Add("不当得利");
			focuss.Add("借款关系");
			focuss.Add("劳动赔偿金");
			focuss.Add("事实与法律依据");
			focuss.Add("过错");
			focuss.Add("股权转让行为效力");
			focuss.Add("偿还欠款");
			focuss.Add("精神抚慰金");
            if (string.IsNullOrEmpty(name))
            {
				return focuss;

			}
            else
            {
				return focuss.Where(p => p.Contains(name)).ToList(); 

			}
		}
		/// <summary>
		/// 不利因素
		/// </summary>
		/// <returns></returns>
		public List<string> getdisadvantages()
		{
			List<string> disadvantages = new List<string>();
			disadvantages.Add("事实不清");

			disadvantages.Add("证据不足");
			disadvantages.Add("程序违法");
			disadvantages.Add("程序不当");

			disadvantages.Add("不属于法院受案范围");
			disadvantages.Add("不属于法院管辖范围");

			disadvantages.Add("主体不适格");
			disadvantages.Add("证据违法或不当");

			disadvantages.Add("当事人诉求不合理");
			disadvantages.Add("无事实依据");

			disadvantages.Add("无法律依据");
			disadvantages.Add("诉讼时效");

			disadvantages.Add("超过诉讼时效");
			disadvantages.Add("诉讼时效中断");

			disadvantages.Add("实体违法");
			disadvantages.Add("定性不当");

			disadvantages.Add("定罪不当");
			disadvantages.Add("适用法律不当");


			disadvantages.Add("量刑不当");
			disadvantages.Add("控判罪名不同");
			return disadvantages;
		}

		/// <summary>
		/// 量刑理由
		/// </summary>
		/// <returns></returns>
		public string[] getstatusCriminal()
		{
			return new string[20] { "坦白", "当庭认罪", "自愿认罪", "悔罪", "自首", "积极赔偿", "取得谅解", "退赃", "退赔", "累犯", "从犯", "犯罪前科", "犯罪未遂", "立功", "和解", "未成年人犯罪", "犯罪预备", "犯罪中止", "教唆", "胁从" };
		}
		/// <summary>
		/// 主刑法
		/// </summary>
		/// <returns></returns>
		public string[] getmainCriminal()
		{
			return  new string[5] { "有期徒刑", "拘役", "无期徒刑", "管制", "死刑" };
		}
		/// <summary>
		/// 副刑法
		/// </summary>
		/// <returns></returns>
		public string[] getfuCriminal()
		{
			return new string[4] { "罚金", "剥夺政治权利", "没收财产", "驱逐出境" };
		}
		/// <summary>
		/// 减刑
		/// </summary>
		/// <returns></returns>
		public string[] getchangeCriminal()
		{
			return new string[2] { "减刑", "假释" };
		}
		/// <summary>
		/// 不予起诉
		/// </summary>
		/// <returns></returns>
		public string[] getnoxingCriminal()
		{
			return new string[1] { "免予刑事处罚" };
		}

      
    }

	public class docType
	{
		public string code { get; set; }  //"01",
		public string name { get; set; }  //"判决书"
	}

	public class region
	{
		public region()
		{
			courts = new List<courtFullName>();
		}
		public string dataValue { get; set; }  //"北京市",
		public string fyCode { get; set; }  //"100"
		public long? count { get; set; }  //"100"
		public List<courtFullName> courts { get; set; }
	}

	//public class judgeProcess
	//{
	//	public string parent { get; set; }  //"1",
	//	public string text { get; set; }  //"民事一审",
	//	public string id { get; set; }  //"10",
	//}

}
